const { data } = require('autoprefixer');
const httpClient = require('./httpClient');

const pk = "a1Vtf1BLhjM"
const pn = "273滚筒标准版2_0版"
const api_apply_device = 'https://mobiledev.utcook.com/catering/iot/device/apply'
const api_login = 'https://oauthdev2.utcook.com/uaa/oauth/token'
const username = 'iot_utcook'
const password = 'Ut123456'

// 申请设备
async function applyIotDevice(num) {
    let applyRes = []
    token = await httpClient.obationAccessToken(api_login, username, password)

    for (let i = 0; i < num; i++) {
        let result = await httpClient.httpPost(api_apply_device, {"productKey": pk}, token)
        console.log("申请设备成功：" + JSON.stringify(result))
    
        applyRes.push({
            pk: result.data.productKey,
            dn: result.data.deviceName,
            ds: result.data.deviceSecret,
            cgid: result.data.deviceCgid,
            pn: pn,
            deviceAlias: pn + Date.now()
        })
    }
    console.log("批量申请设备：" + JSON.stringify(applyRes))
    return applyRes
}


 applyIotDevice(50)


module.exports = {
    applyIotDevice
}